package com.nextbus.adapter;

import java.util.List;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nextbus.main.R;
import com.nextbus.model.ToggleModeLineInfo;

/**
 * ArrayAdpater 适合大容量Array， 这里使用BaseAdapter就够了
 * @author Administrator
 *
 */
public class ToggleModeAdapter extends BaseAdapter {
    private Context context;
    private LayoutInflater inflater;
    private List<ToggleModeLineInfo> items;
    
    public ToggleModeAdapter(Context context, List<ToggleModeLineInfo> items) {
        super();
        inflater = LayoutInflater.from(context);
        this.context = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    /**
     * 得到spinner图标
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView == null) {
            convertView = inflater.inflate(R.layout.togglemodelineinfo, null);
        }
        ImageView image = (ImageView) convertView.findViewById(R.id.icon_dropdown);
        Drawable drawable = this.context.getResources().getDrawable(items.get(position).getDrawable());
        image.setImageDrawable(drawable);
        return image;
    }
    
    /**
     * 点击spinner图标后显示dropdown
     */
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        super.getDropDownView(position, convertView, parent);
        if(convertView == null) {
            convertView = inflater.inflate(R.layout.togglemodelineinfo, null);
        }
        
        ImageView image = (ImageView) convertView.findViewById(R.id.icon_dropdown);
        Drawable drawable = this.context.getResources().getDrawable(items.get(position).getDrawable());
        image.setImageDrawable(drawable);
        TextView text = (TextView) convertView.findViewById(R.id.text_dropdown);
        text.setText(items.get(position).getString());
        return convertView;
    }
   
 
    
    
}

